home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk2.zip / LST14-13.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  83 lines

  1. ;
  2. ; *** Listing 14-13 ***
  3. ;
  4. ; Demonstrates that it's much slower to scan a table
  5. ; in a loop than to use REP SCASW; look-up tables should
  6. ; be designed so that repeated string instructions can be
  7. ; used.
  8. ;
  9.     jmp    Skip
  10. ;
  11. ; Branches to the routine corresponding to the key code in
  12. ; AX. Simply returns if no match is found.
  13. ;
  14. ; Input:
  15. ;    AX = 16-bit key code, as returned by the BIOS
  16. ;
  17. ; Output: none
  18. ;
  19. ; Registers altered: CX, DI, ES
  20. ;
  21. ; Direction flag cleared
  22. ;
  23. ; Table of 16-bit key codes this routine handles, each
  24. ; paired with the address to jump to if that key code is
  25. ; found.
  26. ;
  27. KeyLookUpTable    label    word
  28.     dw    1e41h, HandleA_Z, 3042h, HandleA_Z    ;A-B
  29.     dw    2e43h, HandleA_Z, 2044h, HandleA_Z    ;C-D
  30.     dw    1245h, HandleA_Z, 2146h, HandleA_Z    ;E-F
  31.     dw    2247h, HandleA_Z, 2347h, HandleA_Z    ;G-H
  32.     dw    1749h, HandleA_Z, 244ah, HandleA_Z    ;I-J
  33.     dw    254bh, HandleA_Z, 264ch, HandleA_Z    ;K-L
  34.     dw    324dh, HandleA_Z, 314eh, HandleA_Z    ;M-N
  35.     dw    184fh, HandleA_Z, 1950h, HandleA_Z    ;O-P
  36.     dw    1051h, HandleA_Z, 1352h, HandleA_Z    ;Q-R
  37.     dw    1f53h, HandleA_Z, 1454h, HandleA_Z    ;S-T
  38.     dw    1655h, HandleA_Z, 2f56h, HandleA_Z    ;U-V
  39.     dw    1157h, HandleA_Z, 2d58h, HandleA_Z    ;W-X
  40.     dw    1559h, HandleA_Z, 2c5ah, HandleA_Z    ;Y-Z
  41. KEY_LOOK_UP_TABLE_LEN_IN_ENTRIES equ (($-KeyLookUpTable)/4)
  42. ;
  43. VectorOnKey    proc    near
  44.     mov    di,cs
  45.     mov    es,di
  46.     mov    di,offset KeyLookUpTable
  47.             ;point ES:DI to the table of keys
  48.             ; we handle, which is in the same
  49.             ; code segment as this routine
  50.     mov    cx,KEY_LOOK_UP_TABLE_LEN_IN_ENTRIES
  51.             ;# of entries to scan
  52.     cld
  53. VectorOnKeyLoop:
  54.     scasw
  55.     jz    VectorOnKeyJump    ;we've found the key code
  56.     inc    di        ;point to the next entry
  57.     inc    di
  58.     loop    VectorOnKeyLoop
  59.     ret            ;the key code is not in the
  60.                 ; table, so we're done
  61. VectorOnKeyJump:
  62.     jmp    word ptr cs:[di]
  63.             ;jump to the routine for this key
  64. HandleA_Z:
  65.     ret
  66. VectorOnKey    endp
  67. ;
  68. Skip:
  69.     call    ZTimerOn
  70.     mov    ax,1e41h
  71.     call    VectorOnKey    ;look up 'A'
  72.     mov    ax,1749h
  73.     call    VectorOnKey    ;look up 'I'
  74.     mov    ax,1f53h
  75.     call    VectorOnKey    ;look up 'S'
  76.     mov    ax,2c5ah
  77.     call    VectorOnKey    ;look up 'Z'
  78.     mov    ax,0
  79.     call    VectorOnKey    ;finally, look up a key
  80.                 ; code that's not in the
  81.                 ; table
  82.     call    ZTimerOff
  83.